package com.matrix.order.infrastructure.gateway.acl;

import com.matrix.order.domain.model.Order;
import com.matrix.order.domain.model.OrderPayment;
import com.matrix.order.infrastructure.payment.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author 有点甜
 * @since 2025/8/2
 */
@Component
@RequiredArgsConstructor
public class PaymentAcl {

    private final PaymentService paymentService;

    public String requestPayment(Order order) {
        return paymentService.createNativePayment(order.getOrderNo(), order.getActualAmount(), "餐饮订单-" + order.getOrderNo());
    }

    public String requestPaymentForAdditionalDish(OrderPayment payment) {
        return paymentService.createNativePayment(payment.getPaymentNo(), payment.getAmount(), "加菜-" + payment.getPaymentNo());
    }

    public void requestRefund(Order order, BigDecimal amount, String reason) {
        paymentService.refund(order.getOrderNo(), amount, reason);
    }

    public void closePayment(String orderNo) {
        paymentService.closeOrder(orderNo);
    }
}
